package com.gulimall.order.vo;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

public class OrderConfirmVo {
    //收货地址
    @Setter @Getter
    List<MemberAddressVo> addressVos;
    //所有选中的购物项
    @Setter @Getter
    List<OrderItemVo> items;

    @Setter @Getter
    Map<Long,Boolean> stocks;

    //发票信息。。。

    //优惠卷信息。。

    /**
     * 积分
     */
    @Setter @Getter
    private Integer integration;

    //放重令牌
    @Setter @Getter
    private String orderToken;

    public Integer getCount(){
        Integer i = 0;
        if (items != null){
            for (OrderItemVo item : items) {
                i+=item.getCount();
            }
        }
        return i;
    }


    //订单总额

    private BigDecimal total;

    public BigDecimal getTotal() {
        BigDecimal sum = new BigDecimal("0");
        if (items !=null) {
            for (OrderItemVo item : items) {
                BigDecimal multiply = item.getPrice().multiply(new BigDecimal(item.getCount().toString()));
                sum = sum.add(multiply);
            }
        }
        return sum;
    }

    //应付的价格
    private BigDecimal payPrice;


    public BigDecimal getPayPrice() {
        BigDecimal sum = new BigDecimal("0");
        if (items !=null) {
            for (OrderItemVo item : items) {
                BigDecimal multiply = item.getPrice().multiply(new BigDecimal(item.getCount().toString()));
                sum = sum.add(multiply);
            }
        }
        return sum;
    }
}
